package com.tencent.sr.iris.basic.saas.common.utils;

import com.tencent.sr.rmall.common.exception.code.BaseErrorCode;
import com.tencent.sr.rmall.common.exception.code.ErrorCode;
import com.tencent.sr.rmall.common.primitive.HttpResult;

/**
 * @author nixiaolin
 * @date 2022/11/13 15:34
 */
public abstract class HttpUtils {

    /**
     * 处理结果
     *
     * @param result
     */
    public static <T> T handleResult(HttpResult<T> result) {
        boolean success = result != null;
        AssertUtils.isTrue(success, BaseErrorCode.SYSTEM_ERROR);

        success = result.isSuccess();
        AssertUtils.isTrue(success, new ErrorCode() {
            @Override
            public String getCode() {
                return result.getCode();
            }

            @Override
            public String getDescription() {
                return result.getMsg();
            }
        });

        return result.getData();
    }
}
